package com.juai.centralkitchen.activity;

import android.content.Intent;
import android.os.Handler;
import android.os.Message;

import androidx.annotation.NonNull;

import com.bridge.common.base.BaseActivity;
import com.bridge.common.utils.SpUtils;
import com.bridge.common.utils.UltimateBarXUtils;
import com.juai.centralkitchen.R;

/**
 * @ClassName SplashActivity
 * @Description TODO 启动页
 * @Author biekangdong
 * @CreateDate 2021/5/12 19:25
 * @Version 1.0
 * @UpdateDate 2021/5/12 19:25
 * @UpdateRemark 更新说明
 */
public class SplashActivity extends BaseActivity {

    @Override
    protected int layoutId() {
        return R.layout.activity_splash;
    }


    private int count = 2;
    Handler handler = new Handler() {
        @Override
        public void handleMessage(@NonNull Message msg) {
            super.handleMessage(msg);
            if (msg.what == 0) {
                count--;
                if (count > 0) {
                    sendEmptyMessageDelayed(0, 1000);
                }else {
                    if((int)SpUtils.getData(mContext,SpUtils.ISLOGIN,0)==1){
                        toMainActivity();
                    }else {
                        toLoginActivity();
                    }

                }

            }else  if (msg.what == 2) {

            }
        }
    };

    public void toLoginActivity(){
        startActivity(new Intent(this,LoginActivity.class));
        finish();
    }

    public void toMainActivity(){
        startActivity(new Intent(this,MainActivity.class));
        finish();
    }


    @Override
    protected void initView() {

        handler.sendEmptyMessageDelayed(0, 1000);

    }

    @Override
    protected void setListenner() {

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        handler.removeCallbacksAndMessages(null);
    }
}
